package com.jpxx.netty.marshalling;

import io.netty.channel.ChannelHandlerAdapter;
import io.netty.channel.ChannelHandlerContext;
import io.netty.util.ReferenceCountUtil;

public class ClientHandler extends ChannelHandlerAdapter{  


	@Override  
	public void channelActive(ChannelHandlerContext ctx) {  
		System.out.println("Cllent  go````");  
	}  

	@Override  
	public void channelRead(ChannelHandlerContext ctx, Object msg) {  
		try {
			Resp resp = (Resp) msg;  
	    	System.out.println("server:"+resp.getId()+".."+resp.getName()+".."+resp.getResponseMessage());
		} finally{
			//根服务端的区别，不释放的话数据会撑爆（必须）
			//服务端有写操作会自动释放，只有读没有写操作就需要手动释放
			ReferenceCountUtil.release(msg);//ByteBuf释放它
		}
		
	}
	
	


	@Override
	public void channelReadComplete(ChannelHandlerContext ctx) throws Exception {
		System.out.println("读取完毕");  
	}

	@Override  
	public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) {  
		cause.printStackTrace();  
		ctx.close();  
	}  

}  